package com.qgzj.common.utils;

import java.util.Random;

/**
 * @ClassName RandomIDUtils
 * @Description TODO
 * @DATE 2019-11-20 22:08
 **/
public class RandomIDUtils {


    public static String getRandomId(){
        String s = RandomIDUtils.getRandomStr(2) + DateUtils.getLongFormatNow() + RandomIDUtils.getRandomStr(3);
        return s;
    }


    public static String getRandomStr(int n){
        String str = "";
        Random rand = new Random();
        for(int i=0;i<n;i++){
            int num = rand.nextInt(3);
            switch(num){
                case 0:
                    char c1 = (char)(rand.nextInt(26)+'a');//生成随机小写字母
                    str += c1;
                    break;
                case 1:
                    char c2 = (char)(rand.nextInt(26)+'A');//生成随机大写字母
                    str += c2;
                    break;
                case 2:
                    str += rand.nextInt(10);//生成随机数字
            }
        }
        return str;
    }


}
